home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: server.blaze.net.au!csource!not-for-mail
- From: Andrew.Nesbit@f396.n634.z3.fidonet.org (Andrew Nesbit)
- Subject: help with pi algorithm
- Sender: news@blaze.net.au (news)
- Organization: FidoNet: ZWSBBS +61-3-98276881 28800bps Multiline
- Message-ID: <0fc_9601240111@csource.blaze.net.au>
- X-Nntp-Posting-Host: csource.blaze.net.au
- Date: Tue, 23 Jan 1996 04:44:36 GMT
-
- Hi all!
-
- I am a newbie C programmer trying to write an algorithm to work out the
- value of pi fairly accurately. I have written the following code, but I'm
- not sure whether it's considered 'nasty' programming, or whether it could
- be written to run more quickly.
-
- #include <stdio.h>
- main()
- {
- long double pi = 0;
- long int = count;
- for (count = 1; count <= 300000; count += 4) {
- pi += 4.0 / count; pi -= 4.0 / (count + 2);
- }
- printf("Value of pi is approx %.19Lf)", pi);
- return 0;
- }
-
- Any comments please???
-
- Also, are there any 'standard' algorithm books which would demonstrate this
- sort of programming technique?
-
- Thanks very much,
- Andrew Nesbit
-
- --
- Andrew.Nesbit@f396.n634.z3.fidonet.org, Andrew Nesbit 3:634/396 (FidoNet)
-
-